<?php
	include('header.php');
?>
<?php
	$id="";
	if(isset($_GET['id'])){
		$id = mysql_real_escape_string($_GET['id']); 
	}else{
		?>
		<script>
			history.go(-1);
		</script>
		<?php
	}
?>
<script>
	
	$(function() {
		
		//set ready initiate
		var recID = $("#receiverdd option:selected").val();
		var data = 'recID='+recID;
		$.ajax({
			url: "ajax/receiver.php",  
			type: "GET",        
			data: data,     
			cache: false,
			success: function (result) {  
				if(result != '-1' && result.indexOf(",") != -1){
					var nameEnt = result.split(",");
					if(nameEnt[1] != "" && nameEnt[1].length > 0 ){
						var addr = nameEnt[1];
						var addrSplit = addr.split("-");
						$('#recpostcode').val(addrSplit[0]);
						$('#reccity').val(addrSplit[1]);
						$('#recstate').val(addrSplit[2]); 
					}
					
				}else if(result == '-1'){
					$('#recpostcode').val('');
					$('#reccity').val('');
					$('#recstate').val(''); 
					$('#divAddReceiver').show(); 
				}else{
					$('#recpostcode').val('');
					$('#reccity').val('');
					$('#recstate').val(''); 
					$('#divUpdReceiver').show(); 
				}
			}       
		});
		

	});
</script>

		<!--[if !IE]>start content<![endif]-->
		<div id="content">
			<div class="inner">
				<!--[if !IE]>start section<![endif]-->
				<?php
					
					
				
				?>
				<!--[if !IE]>end section<![endif]-->
				
				<!--[if !IE]>start section<![endif]-->
				<div class="section">
					
					<!--[if !IE]>start title wrapper<![endif]-->
					<div class="title_wrapper">
						<span class="title_wrapper_top"></span>
						<div class="title_wrapper_inner">
							<span class="title_wrapper_middle"></span>
							<div class="title_wrapper_content">
								<h2>View Package</h2>
								
							</div>
						</div>
						<span class="title_wrapper_bottom"></span>
					</div>
					<!--[if !IE]>end title wrapper<![endif]-->
					
					<!--[if !IE]>start section content<![endif]-->
					<div class="section_content">
						<span class="section_content_top"></span>
						
						<div class="section_content_inner">
						
						<?php
						$Qtpd= "select * from  transport_package_delivering	where tpd_id = '$id' ";
						$Rtpd = $db->sql_list($Qtpd);
						
						?>
						<!--[if !IE]>start forms<![endif]-->
						<form action="" method="POST" class="search_form general_form">
							
							<!--[if !IE]>start fieldset<![endif]-->
							<fieldset>
								<!--[if !IE]>start forms<![endif]-->
								<div class="forms">
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>Status:</label>
									<div class="inputs">
										<span class="input_wrapper" style="border:none; width:400px;">
										<input name="tpd_status"  maxlength="50" readonly class="text" value="<?php echo getStatus($Rtpd['tpd_status']); ?>" type="text" /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>Status Remarks :</label>
									<div class="inputs">
										<span class="input_wrapper" style="width:400px;">
											<textarea name="tpd_status_remarks" style="width: 399px; height: 30px; border:none;" disabled><?php echo $Rtpd['tpd_status_remarks']; ?></textarea>
										</span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								
								<?php if($Rtpd['tpd_delivered_date'] != '') {?>
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>Date Start Deliver:</label>
									<div class="inputs">
										<span class="input_wrapper" style="border:none; width:400px;">
										<input name="tpd_status"  maxlength="50" readonly class="text" value="<?php echo $Rtpd['tpd_delivered_date']; ?>" type="text" /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								<?php } ?>
								
								<?php if($Rtpd['tpd_delivered_complete_date'] != '') {?>
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>Date Completed Sent:</label>
									<div class="inputs">
										<span class="input_wrapper" style="border:none; width:400px;">
										<input name="tpd_status"  maxlength="50" readonly class="text" value="<?php echo $Rtpd['tpd_delivered_complete_date']; ?>" type="text" /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								<?php } ?>
								
								<?php if($Rtpd['tpd_delivered_cancel_date'] != '') {?>
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>Date Cancel Package:</label>
									<div class="inputs">
										<span class="input_wrapper" style="border:none; width:400px;">
										<input name="tpd_status"  maxlength="50" readonly class="text" value="<?php echo $Rtpd['tpd_delivered_cancel_date']; ?>" type="text" /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								<?php } ?>
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>TDN No. :</label>
									<div class="inputs">
										<span class="input_wrapper" style="border:none; width:400px;">
											<input name="tpd_tdn_no"  readonly class="text" value="<?php echo $Rtpd['tpd_tdn_no']; ?>" type="text" /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>DO No. :</label>
									<div class="inputs">
										<span class="input_wrapper" style="border:none;width:400px;">
											<input name="tpd_do_ref"  maxlength="20" readonly class="text" value="<?php echo $Rtpd['tpd_do_ref']; ?>" type="text" /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>Quantity :</label>
									<div class="inputs">
										<span class="input_wrapper" style="border:none;width:400px;">
											<input name="tpd_qty" maxlength="5" readonly class="text numbersOnly" value="<?php echo $Rtpd['tpd_qty']; ?>" type="text" /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>Type :</label>
									<div class="inputs">
										<span class="input_wrapper" style="border:none;width:400px;">
											<input name="tpd_qty_type" maxlength="10" readonly class="text" value="<?php echo $Rtpd['tpd_qty_type']; ?>" type="text" /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								
								
								</div>
								<!--[if !IE]>end forms<![endif]-->
								
							</fieldset>
							<!--[if !IE]>end fieldset<![endif]-->
							
							<!--[if !IE]>start fieldset<![endif]-->
							<fieldset>
								<!--[if !IE]>start forms<![endif]-->
								<div class="forms">
								<h3>Sender Information</h3>
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>Sender :</label>
									<div class="inputs">
										<span class="input_wrapper select_wrapper" style="width:400px;" >
											<select name="senderdd" id="senderdd" class="ui-widget ui-widget-content ui-corner-left" disabled>
												<?php
												
												$qList= "select * from entity where ent_old_id is not null ";
												$rList = $db->sql_fetch($qList);
												echo '<option value="" '; if($Rtpd['tpd_sender_ent_id']=="") echo 'selected'; echo'>Please Select</option>';
												foreach ($rList as $i) {
													echo '<option value="'.$i['ent_id'].'" '; if($Rtpd['tpd_sender_ent_id']== $i['ent_id']) echo 'selected'; echo'>'.$i['ent_code'].' - '.$i['ent_short_name'].'</option>';
												}
												?>
											</select>
										</span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								</div>
								<!--[if !IE]>end forms<![endif]-->
								
							</fieldset>
							<!--[if !IE]>end fieldset<![endif]-->
							
							<!--[if !IE]>start fieldset<![endif]-->
							<fieldset>
								<!--[if !IE]>start forms<![endif]-->
								<div class="forms">
								<h3>Receiver Information</h3>
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>Receiver :</label>
									<div class="inputs">
										<span class="input_wrapper select_wrapper"  style="width:400px;">
											<select name="receiverdd" id="receiverdd" class="ui-widget ui-widget-content ui-corner-left" disabled>
												<?php
												
												$qList= "select * from entity where ent_old_id is  null ";
												$rList = $db->sql_fetch($qList);
												echo '<option value="" '; if($Rtpd['tpd_receiver_ent_id']=="") echo 'selected'; echo'>Please Select</option>';
												foreach ($rList as $i) {
													echo '<option value="'.$i['ent_id'].'" '; if($Rtpd['tpd_receiver_ent_id']== $i['ent_id']) echo 'selected'; echo'>'.str_replace("<","&lt;",$i['ent_short_name']).'</option>';
												}
												?>
											</select>
										</span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>Postcode :</label>
									<div class="inputs">
										<span class="input_wrapper" style="border:none;width:400px;"><input readonly id="recpostcode"   class="text " value="" type="text"  /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								
								
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>City :</label>
									<div class="inputs">
										<span class="input_wrapper" style="border:none;width:400px;"><input readonly id="reccity"   class="text " value="" type="text"  /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>State :</label>
									<div class="inputs">
										<span class="input_wrapper" style="border:none;width:400px;"><input readonly id="recstate"  class="text " value="" type="text"  /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								
								</div>
								<!--[if !IE]>end forms<![endif]-->
								
							</fieldset>
							<!--[if !IE]>end fieldset<![endif]-->
							
							<?php /* Get data. */
											$qListTrn= "select count(*) FROM transport t, person p, person_transport_delivering ptd, transport_package_delivering tpd
														WHERE
												tpd.tpd_trn_id = t.trn_id
													AND t.trn_id = ptd.ptd_trn_id
													AND p.per_id = ptd.ptd_person_per_id
													AND tpd.tpd_delivered_date = ptd.ptd_date_assign_driver
													AND tpd.tpd_id = '$Rtpd[tpd_id]' ";
											$rListTrnTot = $db->sql_total($qListTrn);
							?>
							<?php if($rListTrnTot == 1){ ?>	
							<!--[if !IE]>start fieldset<![endif]-->
							<fieldset>
								<!--[if !IE]>start forms<![endif]-->
								<div class="forms">
								<h3>Transport Information</h3>
								
								<?php /* Get data. */
												$qListTrn= "select * FROM transport t, person p, person_transport_delivering ptd, transport_package_delivering tpd
															WHERE
													tpd.tpd_trn_id = t.trn_id
													AND t.trn_id = ptd.ptd_trn_id
													AND p.per_id = ptd.ptd_person_per_id
													AND tpd.tpd_delivered_date = ptd.ptd_date_assign_driver
													AND tpd.tpd_id = '$Rtpd[tpd_id]'  ";
												$rListTrn = $db->sql_list($qListTrn);
								?>
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>Transport  :</label>
									<div class="inputs">
										<span class="input_wrapper" style="border:none;width:400px;"><input readonly id="Transport"  class="text " value="<?php echo $rListTrn['trn_plate_no']; ?>" type="text"  /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>Driver  :</label>
									<div class="inputs">
											<span class="input_wrapper" style="border:none;width:400px;"  ><input readonly id="Driver"  class="text " value="<?php echo $rListTrn['per_full_name']; ?>" type="text"  /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>Date Assign Driver  :</label>
									<div class="inputs">
											<span class="input_wrapper" style="border:none;width:400px;"  ><input readonly id="DateDriver"  class="text " value="<?php echo $rListTrn['ptd_date_assign_driver']; ?>" type="text"  /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								
								<!--[if !IE]>start row<![endif]-->
								<div class="row">
									<label>Remarks Assign Driver  :</label>
									<div class="inputs">
											<span class="input_wrapper" style="border:none;width:400px;"  ><input readonly id="AssDriver"  class="text " value="<?php if($rListTrn['ptd_remarks'] == '' ){echo 'N/A'; } else { echo $rListTrn['ptd_remarks']; } ?>" type="text"  /></span>
									</div>
								</div>
								<!--[if !IE]>end row<![endif]-->
								
								</div>
								<!--[if !IE]>end forms<![endif]-->
								
							</fieldset>
							<!--[if !IE]>end fieldset<![endif]-->
							<?php } ?>
							
							
						</form>
						
						<!--[if !IE]>end forms<![endif]-->
						
						</div>
						
						<span class="section_content_bottom"></span>
					</div>
					<!--[if !IE]>end section content<![endif]-->
				</div>
				<!--[if !IE]>end section<![endif]-->
				
				
				
				
				
				
					
				
			</div>
		</div>
		<!--[if !IE]>end content<![endif]-->

<?php
	include('footer.php');
?>